-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use aiohasupervisor for addon info calls #125926
Conversation
5c16f0c
to
ef4b501
Compare
Not sure how the errors in the hassio/issues tests didn't show up when I was running them locally but I'll fix those. The bluetooth ones I'm seeing the same failures when I switch to dev branch locally so I don't think those are a result of this PR? Will circle back. |
ef4b501
to
ff6a53b
Compare
I'm going to call this ready for review. Yes there is a failure in a test in the Plugwise integration but the test appears to be flaky. I ran it locally against dev branch and it failed 2 times in 10 with no changes in between. I opened #126086 for it. |
ff6a53b
to
87f04ee
Compare
self._client = SupervisorClient( | ||
base_url, os.environ.get("SUPERVISOR_TOKEN", ""), session=websession | ||
) | ||
|
||
@property | ||
def client(self) -> SupervisorClient: | ||
"""Return aiohasupervisor client.""" | ||
return self._client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._client = SupervisorClient( | |
base_url, os.environ.get("SUPERVISOR_TOKEN", ""), session=websession | |
) | |
@property | |
def client(self) -> SupervisorClient: | |
"""Return aiohasupervisor client.""" | |
return self._client | |
self.client = SupervisorClient( | |
base_url, os.environ.get("SUPERVISOR_TOKEN", ""), session=websession | |
) |
Why make it protected if you're going to expose it anyway :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because if you do it that way then someone can do this:
hassio = HassIO(...)
hassio.client = SupervisorClient(...)
By making it a property like that client
is read-only on instances of HassIO
. Others can access it to make calls to supervisor, they cannot change its value to something new.
Well They can but they'd have to set hassio._client
in my example above and then linting would tell them not to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not aware if we have places in the code where we explictly do this, let me check with others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, talked with Martin and this would be good in its current form
def get_supervisor_client(hass: HomeAssistant) -> SupervisorClient: | ||
"""Return supervisor client.""" | ||
hassio: HassIO = hass.data[DOMAIN] | ||
return hassio.client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use HassKey in a future PR to add typing to the hass.data
so you can avoid this type overwrite (if wanted)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't aware of that, that would be nice. It would definitely have to be a follow-up PR though as doing that would require a significant refactor to this integration looking at how much we use that currently.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
87f04ee
to
31b51bf
Compare
31b51bf
to
8312ef4
Compare
@@ -43,6 +39,12 @@ class AlreadyConfigured(HomeAssistantError): | |||
"""Raised when the router is already configured.""" | |||
|
|||
|
|||
@callback | |||
def get_addon_manager(hass: HomeAssistant, slug: str) -> AddonManager: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each add-on manager should be a singleton per add-on. We can use the singleton decorator. See other integrations that create add-on managers.
Hi, I just did a fresh installation of HA core from dev using |
We're aware and a solution is under way. |
The missing import problem should be solved by: |
Proposed change
Begin the process of replacing hassio/handler with a published client library on pip in aiohasupervisor. As this is our guidance to all other integration developers, our supervisor integration should follow this as well.
Since the hassio component's internal library is used all over integrations for access to supervisor information replacing handler will likely take a good number of PRs. This PR seeks only to replace the method used for obtaining addon info with the equivalent method from the library.
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: